package edu.neu.swc.skynet.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h1>服务发现</h1>
 */
@Service
@Slf4j
public class NacosClientService {

    private final DiscoveryClient discoveryClient;

    public NacosClientService(DiscoveryClient discoveryClient){
        this.discoveryClient = discoveryClient;
    }

    /**
     * <h1>打印 Nacos Client 信息到日志中</h1>
     * 打印服务的实例信息到日志中
     * 验证Nacos的可用性
     */
    public List<ServiceInstance> getNacosClientInfo(String serviceId){

        log.info("request nacos client to gent service instance info:[{}]", serviceId);
        return discoveryClient.getInstances(serviceId);
    }
}
